package per.zqx.simplest;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Producer
 *
 * @author Sa  2021-03-16 14:05
 */
public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        String QUEUE_NAME = "simple_queue";
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("localhost");
        try (Connection connection = connectionFactory.newConnection()) {
            Channel channel = connection.createChannel();
            String msg = "2233不是2333哦";
            /**
             * queue：队列
             * durable:是否持久化
             * exclusive：是否独占队列
             * autoDelete:是否自动删除队列（空了之后）
             * arguments：其他参数
             */
            channel.queueDeclare(QUEUE_NAME, true, false, false, null);
            channel.basicPublish("", QUEUE_NAME, null, msg.getBytes("utf-8"));
            System.out.println("Producer sent a msg: " + msg);
        }
    }
}
